<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>
    //1. 对象拓展运算符
    function fun1(){
        let person1 = { name: "Amy", age: 15 }
        //1.1 深拷贝
        let someone = {...person1}
        someone.name = "小张"
        console.log("person1.name:",person1.name)
    }
    // fun1()
    //2. map与reduce
    //2.1 map：用于处理数组的每个元素  【***** 非常重要  *****】
    function fun2(){
        let arr = [1,2,3]
        let arr2 = arr.map(m=>{
            return m*2
        })
        console.log("arr2:",arr2)
    }
    // fun2()
    //2.2 reduce 用于对多个元素（数组）进行累加、累积运算
    function fun3() {
        const arr = [1,20,-5,3];
        let sum = arr.reduce((a,b)=>{
            return a + b
            // return a * b
        },1) // 参数1：回调函数，可以对数组进行累积或累加运算，参数2：初始值
        console.log("sum:",sum)
    }
    // fun3()
    //2.3 filter(): 对数组元素进行过滤
    function fun4() {
        //2.3.1 求出给定数组的偶数的个数？
        const arr = [4,1,6,8,5,7,9,12,25,38]
        let arr2 = arr.filter((a)=>{
            return a % 2 === 0
        })
        console.log("arr2:",arr2,",length:",arr2.length)
    }
    fun4()
</script>